<template>
    <div class="container" :style="{ height: height }">
        <div class="demo">
            <wxc-minibar :title="title"
                         background-color="#009ff0"
                         text-color="#FFFFFF"
                         right-text="more"
                         @wxcMinibarLeftButtonClicked="minibarLeftButtonClick"
                         @wxcMinibarRightButtonClicked="minibarRightButtonClick"></wxc-minibar>
        </div>
        <text>达到阿斯顿撒点撒旦撒旦撒撒旦撒大阿瑟的撒</text>
    </div>
</template>

<script>

    import { WxcMinibar } from 'weex-ui';
    const modal = weex.requireModule('modal');
    const stream = weex.requireModule('stream')
    export default {
        components: { WxcMinibar },
        props: ['title'],
        data () {
          return{
              height: '100%',
              getUrl: 'http://192.168.3.18:8080/500/card/all',
              post: 'http://192.168.3.18:8080/500/message/save',
              postData: {
                  title: 'xxwy',
                  content: 'safsaf'
              },
              page: {
                  pageSize: 10,
                  pageNumber: 1
              }
          }
        },
        created () {

//          this.postStreamData()
         // this.getStreamData()
           this.$api.getCard(this.page).then(res => {
               console.log(res)
           })
        },
        methods: {
            minibarLeftButtonClick () {
            },
            minibarRightButtonClick () {
                modal.toast({ 'message': 'click rightButton!', 'duration': 1 });
            },
            getStreamData () {
                let that = this
               stream.fetch({
                   method: 'get',
                   url: this.getUrl,
                   type: 'json',
                   body: this.toParams(this.page)
               }, (ret) => {
                   if (!ret.ok) {
                       modal.toast({
                           'message': "失败",
                           'duration': 2.0
                       })
                   } else {
                       modal.toast({
                           message: JSON.stringify(ret.data),
                           duration: 2.0
                       })
                       console.log(that.page)
                   }
               })
            },
            postStreamData () {

                stream.fetch({
                    method: 'POST',
                    url: this.post,
                    type: 'json',
                    body: JSON.stringify(this.postData),
                    headers:{'Content-Type':'application/x-www-form-urlencoded'}
                }, (ret) => {
                    if (!ret.ok) {
                        modal.toast({
                            'message': "失败",
                            'duration': 2.0
                        })
                    } else {
                        modal.toast({
                            message: JSON.stringify(ret.data),
                            duration: 2.0
                        })

                    }
                })
            },
            toParams(obj) {
                var param = ""
                for(const name in obj) {
                    if(typeof obj[name] != 'function') {
                        param += "&" + name + "=" + encodeURI(obj[name])
                    }
                }
                return param.substring(1)
            }
        }
    };
</script>